<template>
	<view>
		<!-- 第一步选择分类 -->
		<template v-if="step == 1">
			<view class="class flex" v-if="list">
				<scroll-view scroll-y="true" class="nav">
					<view class="nav_item flex f-y-c f-x-c" @click="navAct = index,one_cate_id=item.value" :class="{ act: index == navAct }" v-for="(item, index) in list" :key="index">
						<view class="actLine" v-if="index == navAct"></view>
						<view class="text ellipsis t-c">{{ item.text }}</view>
					</view>
				</scroll-view>
				<scroll-view scroll-y="true" class="shop_list">
					<view class="box">
						<view class="shop_item" v-for="(val, key) in list[navAct].children" :key="key" @click="cate_idval = val.value">
							<view class="title" :class="{'current':cate_idval == val.value}">{{ val.text }}</view>
						</view>
					</view>
					
					
					<view class="info-box" style="margin-top: 24rpx">
						<view class="info-each">
							<view class="">展示视频</view>
							<view class="">
								<!-- <text class="tint">请上传展示视频</text> -->
							</view>
						</view>
						<view class="upimg" style="margin-top: 24rpx;">
							<u-upload
								:fileList="fileList3"
								@afterRead="afterRead"
								@delete="deletePic"
								name="3"
								multiple
								:maxCount="1"
								accept="video"
							>
							<image src="../../static/imgs.png" mode="widthFix"
								style="width: 130rpx;height: 130rpx;">
							</image>
							</u-upload>
						</view>
					</view>
					
					<view class="info-box" style="margin-top: 24rpx">
						<view class="info-each">
							<view class="">视频库视频</view>
							<view class="">
								<!-- <text class="tint">请上传视频库视频</text> -->
							</view>
						</view>
						<view class="upimg" style="margin-top: 24rpx;">
							<u-upload
								:fileList="fileList4"
								@afterRead="afterRead"
								@delete="deletePic"
								name="4"
								multiple
								:maxCount="6"
								accept="video"
							>
							<image src="../../static/imgs.png" mode="widthFix"
								style="width: 130rpx;height: 130rpx;">
							</image>
							</u-upload>
						</view>
					</view>
					<view style="height: 250rpx;width: 1rpx;"></view>

					<view class="bot-box">
						<!-- <view class="btn" @click="save1">发布</view> -->
						<view class="text">点击上方列表，选择一个您擅长的服务，如果上方没有您擅长的服务，可以联系客服：18162456022</view>
						<view class="text" v-if="state == -1"> 审核失败，请重新选择分类提交 </view>
						<view class="btn" @click="save1" v-if="state == -1">重新提交</view>
						<view class="btn" @click="save1" v-else-if="state == 1">确定</view>
						<view class="btn" v-else-if="state == 0">审核中</view>
					</view>
				</scroll-view>
			</view>
		</template>
		
		<!-- 第二步发布 -->
		<template v-if="step == 2">
			<view class="info-box">
				<view class="info-each">
					<view class="">技能标题</view>
					<view class="input">
						<input v-model="name" type="text" placeholder="请输入" />
					</view>
				</view>
				<view class="wire"></view>
				<view class="introduce-box">
					<view class="">技能介绍</view>
					<view class="textarea-box">
						<textarea v-model="content" name="" id="" cols="30" rows="10" placeholder="请输入"></textarea>
					</view>
				</view>
				<view class="wire"></view>
				<view class="info-each">
					<view class="">技能单位</view>
					<fy-picker mode="multiSelector" v-model="data1Value" :range="range1" @confirm="onconfirm1">
					<view class="">
						<text class="tint">{{unit || '请输入或选择单位'}}</text>
						<image src="../../static/right-img.png" mode=""></image>
					</view>
					</fy-picker>
				</view>
				<view class="wire"></view>
				<view class="info-each">
					<view class="">价格</view>
					<view class="input">
						<input v-model="price" type="number" placeholder="请输入" />
						<text>元</text>
					</view>
				</view>
			</view>
			
			<view class="info-box" style="margin-top: 24rpx">
				<view class="info-each">
					<view class="">技能封面图</view>
					<view class="">
						<text class="tint">请上传封面图</text>
					</view>
				</view>
				<view class="upimg-box">
					<view class="upimg">
						<u-upload width="65" height="65" :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple :maxCount="9">
							<image src="../../static/imgs.png" mode="widthFix" style="width: 130rpx; height: 130rpx"></image>
						</u-upload>
					</view>
				</view>
			</view>
			
			<view class="info-box" style="margin-top: 24rpx">
				<view class="info-each">
					<view class="">技能案例</view>
					<view class="">
						<text class="tint">请上传案例</text>
					</view>
				</view>
				<view class="upimg-box">
					<view class="upimg">
						<u-upload width="65" height="65" :fileList="fileList2" @afterRead="afterRead" @delete="deletePic" name="2" multiple :maxCount="9">
							<image src="../../static/imgs.png" mode="widthFix" style="width: 130rpx; height: 130rpx"></image>
						</u-upload>
					</view>
				</view>
			</view>
			
			
			<view class="cotton"></view>
			<view class="btn-box">
				<view class="btn" @click="save">发布</view>
			</view>
		</template>
		
		
		<u-popup :show="show" @close="show = false" mode="center" :round="20">
			<view class="serveBox" v-if="show">
				<view class="serve_tit">
					恭喜你，信息发布成功
				</view>
				<view class="serve_tit2" style="color: #d3d3d3;font-size: 25rpx;margin: 16rpx 0;">
					等待客服人员审核后，即可正常展示
				</view>
				<view class="serve_tit2">
					开启信息置顶，享受信息超级曝光
				</view>
				<view class="tc-img">
					<image :src="oss(meal[0].image)" mode="aspectFill"></image>
				</view>
				<view class="serve_cont">
					
					
					<view style="min-width: 200rpx;text-align: center;border-radius: 20rpx;background-color: #FFF7F5;margin-left: 24rpx;border: 2px solid #FFF7F5;" v-for="i in meal" :class="{active: type === i.id}" @click="select(i)">
						<view style="font-size: 26rpx;padding-top: 32rpx;">{{i.day}}天</view>
						<view style="font-size: 22rpx;color: #FC6605;padding-top: 16rpx;">￥ <text style="font-size: 36rpx;font-weight: 500;">{{i.num}}</text> <text v-if="i.original_num!=0" style="text-decoration: line-through">￥{{i.original_num}}</text> </view>
						<view style="height: 60rpx;width: 1rpx;"></view>
						<view style="background-color: #FF7A7A;color: #FFF;font-size: 24rpx;border-radius: 0 0 20rpx 20rpx;padding: 8rpx 0;"> {{i.day_num}}/天 </view>
					</view>
					
				</view>
				<view class="tc-btn-box">
					<view class="tc-btn1" @click="authTo(`pages/common/paylevel?type=${type}&money=${money}`)">购买置顶</view>
					<view class="tc-btn2" @click="show = false">关闭</view>
				</view>
				<view style="height: 24rpx;width: 1rpx;"></view>
			</view>
		</u-popup>
		
		
		<view class="issue" @click="toVideo">
			拍摄教程
		</view>
	</view>
</template>

<script>
	import FyPicker from '@/components/fy-picker/fy-picker.vue'
export default {
	components: { FyPicker },
	data() {
		return {
			step:0,
			navAct: 0,
			list: '',
			fileList1: [],
			fileList2:[],
			fileList3: [],
			fileList4:[],
			one_cate_id:'',//一级分类id
			cate_idval:'',//分类id
			name: '',
			content: '',
			price: '',
			unit: '',//技能单位
			// unit_price: '',//其它单位
			range1:['次','天','小时','分钟'],//
			data1Value: [],
			// id:'',
			state:1,//分类审核状态
			info:'',
			
			show:false,
			hyinfo: [],
			itemid:'',
			type:0,
			money:'',
			meal:[]
		}
	},
	onLoad(op) {
		if(op.info){
			this.info = JSON.parse(op.info)
			console.log(this.info)
		}
		// this.gainCate_idval()
		this.editPostSkill()
		this.getcate()
		this.getInfo()
	},
	// onShow() {
	// 	this.editPostSkill()
	// },
	methods: {
		toVideo(){
			uni.navigateTo({
				url:'/pages/videoShopping/videoShopping?types=0'
			})
		},
		// select(type,money) {
		// 	this.type = type
		// 	this.money = money
		// },
		select(item) {
			this.type = item.id
			this.money = item.num
		},
		getInfo() {
			uni.$u.http.post('/meallist',{
				mealtype:6
			}).then(res => {
				if (res.code === 1) {
					this.meal = res.data
					this.type = this.meal[0].id
					this.money = this.meal[0].num
				}
			}).catch((res) => {
				
			})
			// uni.$u.http.post('/rechargeuser').then(res => {
			// 	if (res.code === 1) {
			// 		this.hyinfo = res.data;
			// 		this.money = res.data.month
			// 	}
			// }).catch((res) => {
				
			// })
		},
		editPostSkill(){
			uni.$u.http.post('/postskill').then(res => {
				if(res.code == 1) {
					if(res.data){
						this.state = res.data.state
						if(res.data.state == 1){
							uni.setNavigationBarTitle({
								title: '技能发布'
							});
							this.one_cate_id = res.data.one_cate_id
							this.cate_idval = res.data.cate_id
							this.step = 2
						} else {
							this.step = 1
						}
					}else {
						// this.$u.toast('首次发布先选择分类');
						
						uni.setNavigationBarTitle({
							title: '行业选择'
						});
						this.step = 1
					}
				}
				
			}).catch((res) => {
				
			})
		},
		save1() {
			if(!this.cate_idval) {
				uni.$u.toast('请选择分类');
				return
			}
			let video = [];
			this.fileList3.forEach(item => {
				video.push(item.url)
			})
			let videos = [];
			this.fileList4.forEach(item => {
				videos.push(item.url)
			})
			// console.log(this.one_cate_id,this.cate_idval,'分类id')
			uni.$u.http.post('/postskill ', {
				type:'submit',
				cate_id: this.cate_idval,
				one_cate_id:this.one_cate_id,
				video:video.join(','),
				videos:videos.join(',')
			}).then(res => {
				if (res.code == 1) {
					uni.$u.toast(res.msg)
					this.show = true
					this.editPostSkill()
					
				}
			}).catch((res) => {
				if(res.code == 3){
					uni.$u.toast(res.msg)
					setTimeout(() => {
						uni.$u.route({
							url: '/pages/my/renZheng/geren'
						})
					},1000)
				}
			})
		},
		save() {
			if(!this.cate_idval) {
				uni.$u.toast('请选择分类');
				return
			}
			if(this.name === ''){
				uni.$u.toast('请输入技能标题');
				return
			}
			if(this.content === '') {
				uni.$u.toast('请输入技能介绍');
				return
			}
			if(!uni.$u.test.amount(this.price)){
				uni.$u.toast('请输入正确的金额');
				return
			}
			
			
			let images = this.fileList1.map((value) => {
				return value.url
			})
			let images2 = this.fileList2.map((value) => {
				return value.url
			})
			if(images.length === 0) {
				uni.$u.toast('请上传技能封面');
				return
			}
			if(images2.length === 0) {
				uni.$u.toast('请上传案例');
				return
			}
			// let video = [];
			// this.fileList3.forEach(item => {
			// 	video.push(item.url)
			// })
			// let videos = [];
			// this.fileList4.forEach(item => {
			// 	videos.push(item.url)
			// })
			// console.log(video,videos,this.fileList3,this.fileList4)
			uni.$u.http.post('/editPostSkill ', {
				type:'submit',
				cate_id: this.cate_idval,
				name: this.name,
				price: this.price,
				content: this.content,
				unit_price:this.unit,
				images: images.join(','),
				demoimages: images2.join(','),
				one_cate_id:this.one_cate_id,
				// video:video.join(','),
				// videos:videos.join(','),
			}).then(res => {
				if (res.code == 1) {
					uni.$u.toast(res.msg)
					let that = this
					
					
					uni.requestSubscribeMessage({
					  tmplIds: ['Pk6dSBHR0Pobiz6Ng4wZd0AgNep5NxvhFVpuNiZHjEo'],
					  success (res) {
						uni.navigateBack()
					  },
					  fail (e) {
					    uni.navigateBack()
					}})
					uni.navigateBack()
				}
			}).catch((res) => {
				if(res.code == 3){
					uni.$u.toast(res.msg)
					setTimeout(() => {
						// uni.$u.route({
						// 	url: 'pages/my/auth'
						// })
						uni.$u.route({
							url: '/pages/my/renZheng/geren'
						})
					},1000)
				}
			})
		},
		onconfirm1(e){
			this.unit = e.selected[0]
			console.log(e)
		},
		getcate(){
			uni.$u.http.post('/getcitycate ', {}).then(res => {
				if (res.code == 1) {
					this.list = res.data
				}
			}).catch((res) => {
						
			})
		},
		nextStep(){
			if(this.cate_idval){
				this.step = 2
				uni.setNavigationBarTitle({
				  title: '技能发布'
				});
			} else {
				uni.$u.toast('请选择分类');
			}
		},
		// 删除图片
		deletePic(event) {
			this[`fileList${event.name}`].splice(event.index, 1);
		},
		// 新增图片
		async afterRead(event) {
			// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
			let lists = [].concat(event.file);
		
			let fileListLen = this[`fileList${event.name}`].length;
			lists.map((item) => {
				this[`fileList${event.name}`].push({
					...item,
					status: 'uploading',
					message: '上传中'
				});
			})
		
		
			for (let i = 0; i < lists.length; i++) {
				const result = await this.uploadFilePromise(lists[i].url);
		
				console.log(result)
		
		
				if (result) {
					let item = this[`fileList${event.name}`][fileListLen];
					this[`fileList${event.name}`].splice(
						fileListLen,
						1,
						Object.assign(item, {
							status: 'success',
							message: '',
							url: result.url
						})
					)
		
		
					fileListLen++;
				} else {
					this[`fileList${event.name}`].splice(fileListLen, 1);
				}
			}
			console.log(this[`fileList${event.name}`]);
		},
		uploadFilePromise(url) {
			console.log(url);
		
			let that = this;
			return new Promise((resolve, reject) => {
				let a = uni.uploadFile({
					url: that.Upload.uploadurl, // 仅为示例，非真实的接口地址
					filePath: url,
					name: 'file',
					formData: {
						type: 'image',
						token: uni.getStorageSync('token')
					},
					success: (res) => {
						let data = JSON.parse(res.data)
						if (res.statusCode === 200 && data.code === 1 && data.data) {
							resolve(data.data)
						} else {
							resolve()
						}
					}
				});
			});
		}
	}
}

</script>

<style lang="scss">
	page {
		background: #F6F6F6;
	}
.class {
	.nav,
	.shop_list {
		height: calc(100vh - 90rpx);
		overflow: hidden;
		box-sizing: border-box;
		background-color: #FFF;
	}

	.nav {
		background: #f5f5f5;
		width: 216rpx;
		.nav_item {
			padding: 40rpx 0;
			font-size: 28rpx;
			font-weight: 400;
			color: #989898;

			.text {
				width: 190rpx;
			}

			.actLine {
				width: 8rpx;
				height: 28rpx;
				background: #febf4e;
				border-radius: 4rpx;
				margin-right: 15rpx;
			}

			&.act {
				font-size: 32rpx;
				font-weight: 400;
				color: #343434;
				background: #fff;

				.text {
					width: 160rpx;
				}
			}
		}
	}

	.shop_list {
		flex: 1;
		padding: 30rpx 40rpx;

		.box {
			display: flex;
			flex-wrap: wrap;
			align-items: center;
		}
		.shop_item {
			margin-right: 46rpx;
			margin-bottom: 46rpx;
			display: flex;
			flex-direction: column;
			align-items: center;
			&:nth-child(3n + 3) {
				margin-right: 0rpx;
			}

			.cover {
				width: 120rpx;
				height: 120rpx;
			}

			.title {
				// width: 120rpx;
				// width: 142rpx;
				// height: 70rpx;
				font-size: 26rpx;
				font-weight: 500;
				color: #666666;
				padding: 17rpx 32rpx;
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				opacity: 1;
				border: 1rpx solid #F0F0F0;
			}
			.current {
				border: 1rpx solid #febf4e;
			}

			font-size: 28rpx;
			font-weight: 400;
			color: #343434;
		}
	}
}

.bot-box {
	position: fixed;
	bottom: 110rpx;

	.text {
		width: 400rpx;
		// height: 126rpx;
		background: #f6f6f6;
		// margin: auto;
		border-radius: 24rpx 24rpx 24rpx 24rpx;
		opacity: 1;
		font-size: 22rpx;
		padding: 32rpx;
		font-weight: 500;
		color: #666666;
		margin-top: 32rpx;
	}
	.btn {
		width: 480rpx;
		height: 88rpx;
		background: #febf4e;
		border-radius: 44rpx 44rpx 44rpx 44rpx;
		opacity: 1;
		margin: auto;
		font-size: 28rpx;
		text-align: center;
		font-weight: 500;
		color: #333333;
		line-height: 88rpx;
		margin-top: 32rpx;
	}
}


.info-box {
	width: 622rpx;
	padding: 29rpx 32rpx;
	background: #ffffff;
	border-radius: 16rpx 16rpx 16rpx 16rpx;
	opacity: 1;
	margin: auto;

	.info-each {
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-size: 30rpx;
		font-weight: bold;
		color: #333333;

		.input {
			display: flex;
			align-items: center;
			text-align: right;
			font-size: 30rpx;
			font-weight: 500;
			color: #333333;

			text {
				display: inline-block;
				padding-left: 30rpx;
			}
		}

		image {
			width: 32rpx;
			height: 32rpx;
			position: relative;
			top: 7rpx;
			left: 20rpx;
		}
		.tint {
			font-size: 30rpx;
			font-weight: 500;
			color: #999999;
		}
	}
	
	.upimg-box {
		width: 622rpx;
		height: 191rpx;
		background: #F6F6F6;
		border-radius: 24rpx 24rpx 24rpx 24rpx;
		opacity: 1;
		border: 1rpx solid #F0F0F0;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-top: 30rpx;
		.upimg {
			
		}
	}
	

	.wire {
		width: 622rpx;
		height: 1rpx;
		background-color: #f0f0f0;
		margin: auto;
		margin: 30rpx 0;
	}

	.tags-box {
		font-size: 30rpx;
		font-weight: bold;
		color: #333333;
		.tags {
			display: flex;
			margin-top: 24rpx;
			.tag {
				background-color: #f6f6f6;
				font-size: 30rpx;
				padding: 19rpx 48rpx 19rpx 24rpx;
				font-weight: 500;
				color: #333333;
				border-radius: 16rpx 16rpx 16rpx 16rpx;
				margin-right: 24rpx;
				image {
					width: 30rpx;
					height: 30rpx;
					position: relative;
					top: 7rpx;
					left: 20rpx;
				}
			}
		}
	}

	.introduce-box {
		font-size: 30rpx;
		font-weight: bold;
		color: #333333;
		.textarea-box {
			padding: 24rpx 0;
			height: 180rpx;
			font-size: 30rpx;
			font-weight: 500;
			color: #333333;
			textarea {
				height: 180rpx;
			}
		}
	}
}
.cotton {
	height: 150rpx;
}
.btn-box {
	width: 100%;
	position: fixed;
	bottom: 20rpx;
	z-index: 9;

	.btn {
		width: 686rpx;
		height: 98rpx;
		background: #febf4e;
		border-radius: 49rpx 49rpx 49rpx 49rpx;
		opacity: 1;
		margin: auto;
		text-align: center;
		line-height: 98rpx;
		font-size: 30rpx;
		font-weight: 500;
		color: #333333;
	}
}


.serveBox {
				width: 690rpx;
				border-radius: 20rpx;

				.serve_tit {
					margin-top: 30rpx;
					text-align: center;
					font-size: 32rpx;
					color: #333333;
					font-weight: bold;
					line-height: 40rpx;
				}
				.serve_tit2 {
					text-align: center;
					font-size: 32rpx;
					color: #333333;
					font-weight: bold;
					line-height: 32rpx;
				}
				
				.tc-img {
					width: 600rpx;
					margin: auto;
					image {
						width: 600rpx;
						height: 500rpx;
					}
				}
				
				.serve_cont {
					// margin: 0 30rpx;
					// display: flex;
					// flex-wrap: wrap;
					// flex-direction: row;
					
					display: flex;
					margin: 24rpx 0 32rpx 0;
					overflow: hidden;
					overflow-x: auto;
					white-space: nowrap;

					.serve {
						margin: 30rpx 0;
						display: flex;
						flex-direction: column;
						justify-content: center;
						align-items: center;
						margin-right: 20rpx;
						width: 190rpx;
						height: 200rpx;
						box-sizing: border-box;
						border-radius: 20rpx;
						border: 1rpx solid #989898;


						.serve_num {
							margin-bottom: 20rpx;
							font-size: 32rpx;
							font-weight: bold;
							color: #333;
							line-height: 45rpx;
						}

						.serve_hour {
							font-size: 28rpx;
							font-weight: 400;
							color: #323232;
							line-height: 40rpx;
						}
					}

					// .active {
					// 	border: 1rpx solid #FFDF41;
					// }
					.active{
						border: 2px solid #FF7A7A !important;
					}
				}
				
				.tc-btn-box {
					width: 560rpx;
					margin: auto;
					display: flex;
					justify-content: space-between;
					.tc-btn1 {
						width: 220rpx;
						height: 80rpx;
						background-color: #FBBA45;
						border-radius: 10rpx;
						text-align: center;
						line-height: 80rpx;
					}
					.tc-btn2 {
						width: 220rpx;
						height: 80rpx;
						border-radius: 10rpx;
						text-align: center;
						line-height: 80rpx;
						background-color: #9A9A9A;
						color: #FFF;
					}
				}
			}
			
			
			.issue {
					width: 60rpx;
					height: 60rpx;
					background: linear-gradient(180deg, #FECB6F 0%, #FFAE1C 100%);
					border-radius: 0rpx 0rpx 0rpx 0rpx;
					opacity: 1;
					border-radius: 50%;
					font-size: 24rpx;
					font-weight: bold;
					color: #333333;
					padding: 20rpx;
					text-align: center;
					position: fixed;
					right: 32rpx;
					// bottom: 200rpx;
					bottom: 48%;
					z-index: 9;
				}
</style>
